﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using DevExpress.XtraEditors;
using System.Linq;
namespace Exact_Extension
{
    public partial class COETransfer : DevExpress.XtraEditors.XtraForm
    {
        ExactDataContext DS;
        Common common;
        public COETransfer(ExactDataContext _DS)
        {
            InitializeComponent();
            DS = _DS;
            common = new Common(_DS);
        }
        private void LoadData()
        {
            var querySTAssigned = from STAssigned in DS.ISHCMC_StudentCOEAssigneds
                                  select STAssigned;
            this.iSHCMCStudentCOEAssignedBindingSource.DataSource = querySTAssigned;

            var querySTAvailable = from STAvailable in DS.ISHCMC_StudentCOEAvailables
                                   select STAvailable;
            this.iSHCMCStudentCOEAvailableBindingSource.DataSource = querySTAvailable;

        }

        private void btnLoad_Click(object sender, EventArgs e)
        {
            this.LoadData();
        }

        private void btnTransfer_Click(object sender, EventArgs e)
        {
            ISHCMC_StudentCOEAssigned STAssigned = (ISHCMC_StudentCOEAssigned)this.gridView_COEAssigned.GetRow(
                     this.gridView_COEAssigned.GetSelectedRows()[0]);
            ISHCMC_StudentCOEAvailable STAvailable = (ISHCMC_StudentCOEAvailable)this.gridView_COEAvailable.GetRow(
              this.gridView_COEAvailable.GetSelectedRows()[0]);

            MsgCOETransfer msgCOETransfer = new MsgCOETransfer(STAssigned,STAvailable, common);
            msgCOETransfer.StartPosition = FormStartPosition.CenterScreen;
            DialogResult result = msgCOETransfer.ShowDialog();
            if (result == DialogResult.OK)
            {
                MessageBox.Show("Transfer from student " + STAssigned.StudentID + " To Student " + STAvailable.StudentID + " Successfully !!");
                this.LoadData();
            }
            if (result == DialogResult.No)
            {
                MessageBox.Show("Can not transfer COE please you check with administrator again !!");
            }


        }
    }
}